﻿using Hangfire;
//using Hangfire.RecurringJobExtensions;
//using BackgroundService = Hangfire.RecurringJobExtensions.BackgroundService;
using Hangfire.Annotations;
namespace WebAppHangfire.Service
{

    public class MyJob1 : BackgroundService
    {
        private readonly IRecurringJobManager _recurringJobs;
        private readonly ILogger<MyJob1> _logger;

        public MyJob1([NotNull] IRecurringJobManager recurringJobs, [NotNull] ILogger<MyJob1> logger)
        {
            _recurringJobs = recurringJobs ?? throw new ArgumentNullException(nameof(recurringJobs));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }



        //public MyJob1(IRecurringJobManager recurringJobs)
        //{
        //    _recurringJobs = recurringJobs;
        //}

        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _recurringJobs.AddOrUpdate("seconds", () => Console.WriteLine("Hello, seconds!"), "*/15 * * * * *");
            //throw new NotImplementedException();
            return Task.CompletedTask;
        }
    }



}
